# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=glm
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=0.9.9.8
pkgrel=2
pkgdesc="C++ mathematics library for 3D software based on the OpenGL Shading Language (GLSL) specification (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32' 'clangarm64')
url='https://glm.g-truc.net/'
license=('MIT')
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs")
makedepends=("${MINGW_PACKAGE_PREFIX}-cc" "${MINGW_PACKAGE_PREFIX}-cmake")
source=("${_realname}-${pkgver}.tar.gz"::"https://github.com/g-truc/${_realname}/archive/${pkgver}.tar.gz"
        cmake-install-back.patch)
sha256sums=('7d508ab72cb5d43227a3711420f06ff99b0a0cb63ee2f93631b162bfe1fe9592'
            'cc2dff9387d3299b233374c51090713be38412fb8a9464f9dbd64d8edabd45da')

prepare() {
  cd ${_realname}-${pkgver}
  patch -p1 -i ${srcdir}/cmake-install-back.patch
}

build() {
  cd ${srcdir}/${_realname}-${pkgver}
  [[ -d ${srcdir}/build-${MINGW_CHOST} ]] && \
     rm -rf ${srcdir}/build-${MINGW_CHOST}
  mkdir ${srcdir}/build-${MINGW_CHOST}
  cd "${srcdir}/build-${MINGW_CHOST}"

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  ${MINGW_PREFIX}/bin/cmake.exe \
    -G"MSYS Makefiles" \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    -DGLM_TEST_ENABLE=OFF \
    ../${_realname}-${pkgver}

  make
}

package() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  make DESTDIR=${pkgdir} install

  mkdir -p ${pkgdir}${MINGW_PREFIX}/share/doc
  cp -r $srcdir/${_realname}-${pkgver}/doc \
   ${pkgdir}${MINGW_PREFIX}/share/doc/glm
  rm -f ${pkgdir}${MINGW_PREFIX}/include/glm/CMakeLists.txt
  find ${pkgdir}${MINGW_PREFIX} -type f -exec chmod 644 {} \;
  find ${pkgdir}${MINGW_PREFIX} -type d -exec chmod 755 {} \;

  #install -Dm644 ${srcdir}/${_realname}-${pkgver}/util/FindGLM.cmake ${pkgdir}${MINGW_PREFIX}/share/cmake-3.12/Modules/FindGLM.cmake
}
